rm(list=ls())

load("TSCS_data.RData")

# Figure C.1 --------------------------------------------------------------

panel %>% select(downturn,citizen_support,antipluralism_gov_seat_share) %>% 
  mutate(Binary = ifelse(downturn>0,"Downturn","No Dowturn"),
         Downturn = ifelse(downturn>0,downturn,NA)) %>% 
  as.data.frame() -> 
  histogram_data

histogram_data %>% 
  group_by(Binary) %>% 
  summarise(Count = n()) %>%
  filter(!is.na(Binary)) ->
  bar_plot

pdf(file = "fig_c1a.pdf",width = 6,height = 5)

ggplot(bar_plot, aes(x=Binary, y=Count)) + 
  geom_bar(stat = "identity") 

dev.off()

pdf(file = "fig_c1b.pdf",width = 6,height = 5)

ggplot(histogram_data, aes(x=Downturn)) + 
  geom_histogram(binwidth=0.1)  + ylab("Count")

dev.off()

pdf(file = "fig_c1c.pdf",width = 6,height = 5)

ggplot(histogram_data, aes(x=citizen_support)) + 
  geom_histogram(binwidth=0.1) + 
  ylab("Count") +
  xlab("Citizen Support")

dev.off()

pdf(file = "fig_c1d.pdf",width = 6,height = 5)

ggplot(histogram_data, aes(x=antipluralism_gov_seat_share)) + 
  geom_histogram(binwidth=0.05) + 
  ylab("Count") + 
  xlab("Anti-pluralist Government")

dev.off()
